/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1602.czq.dao.impl;

import edu.fjut.se1602.czq.dao.PetDao;
import edu.fjut.se1602.czq.entity.Pet;
import edu.fjut.se1602.czq.util.DBUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author asus
 */
public class PetDaoImpl implements PetDao {

    @Override
    public List<Pet> getAllPet() {
        List<Pet> arraylist = new ArrayList<Pet>();
        try {
            Connection con = DBUtil.getConnection();
            ResultSet rs = con.createStatement().executeQuery("select * from pet");
            while (rs.next()) {
                Pet pet = new Pet();
                pet.setID(rs.getInt("ID"));
                pet.setName(rs.getString("name"));
                pet.setTypeName(rs.getString("typeName"));
                pet.setHealth(rs.getInt("health"));
                pet.setLove(rs.getInt("love"));
                pet.setBirthday(rs.getDate("birthday"));
                pet.setOwner_id(rs.getInt("owner_id"));
                pet.setStore_id(rs.getInt("store_id"));
                pet.setPrice(rs.getDouble("price"));
                arraylist.add(pet);

            }
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(PetDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return arraylist;
    }

}
